package com.cy;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@SpringBootApplication
public class NacosProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(NacosProviderApplication.class, args);
    }

    //value注解用于告诉spring,从application.yml,application.properties中取出8081端口
    @Value("${server.port}")
    private String server;

    @RestController
    public class ProviderController {
        @GetMapping("/provider/echo/{string}")
        public String doEcho(@PathVariable String string, HttpServletRequest request) {
            //打印-gateway---网关的局部过滤器设置(添加请求头--插入自定义的参数)
            //获取网关配置的过滤器的请求头的name
            Enumeration<String> headerNames = request.getHeaderNames();
//迭代请求头,获取每一个请求头的name
            while (headerNames.hasMoreElements()) {
                String headerName = headerNames.nextElement();//获取每一个请求头的name
                String headervalue = request.getHeader(headerName);
                System.out.println(headerName + "/" + headervalue);
            }
            //获取输入的url的pageSize的值
            String pageSize = request.getParameter("pageSize");
            System.out.println("pageSize=" + pageSize);
            return "nacos-provider" + server + "say:" + string;
        }
    }
}

